import Vue from 'vue'
import co from 'co'
import * as Util from '../../components/Util'

let getSplitInfoGen = function * (val) {
  let splits = yield Vue.resetpost('rs/sql/querySingleTable', {data: {items: 'f_user_id', tablename: 't_userfiles', condition: `f_meter_id='${val}'`}}, {resolveMsg: null, rejectMsg: '验证分表信息时:获取总表下的分表编号出错!!!'})
  // 验证分表信息有没有在这个时间内未抄的
  let hasUnHand = false
  for (let i = 0; i < splits.data.length; i++) {
    let param = {
      // 由于这条总表记录还没有抄。录入日期默认当前日期
      f_input_date: Util.toStandardTimeString(),
      f_user_id: splits.data[i].f_user_id
    }
    let split = yield Vue.resetpost('rs/logic/splitUnHandInfo', {data: {totalInfo: param}}, {resolveMsg: null, rejectMsg: '验证分表信息时:获取分表未抄表信息出错!!!'})
    console.log('拿到单个分表的抄表信息。。。', split)
    if (split.data.length === 0) {
      hasUnHand = true
      break
    }
  }
  return hasUnHand
}

let HandService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.HandService = Vue.prototype.$HandService = HandService
  },

  getSplitInfo(f_user_id) {
    return co(getSplitInfoGen(f_user_id))
  }
}

export default HandService
